package yl.hs.bmipfull.controllers.driverApp;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import yl.hs.bmipfull.controllers.ControllerBase;
import yl.hs.bmipfull.service.system.ISiteMessageMainService;
import yl.hs.bmipfull.service.system.ISiteMessageReceiptService;
import yl.hs.bmipfull.utils.HsApp;
import yl.hs.bmipfull.viewmodels.PageQuery;
import yl.hs.bmipfull.viewmodels.WebResult;

/**
 * @author 谢东
 * @apiNote 司机站内信通知
 * @since 2022/5/20 17:23 创建
 */
@RequestMapping("/api/driverApp/driverMessage")
@Api(value = "司机站内信通知Web接口", tags = "司机端app——司机站内信通知Web接口")
@RestController
public class DriverMessageController extends ControllerBase {

    @Autowired
    ISiteMessageReceiptService service;

    @ApiOperation(value = "查询站内信息收件信息", notes = "分页查询站内信息收件信息")
    @RequestMapping(value = "/{rowNum}/{page}", method = RequestMethod.POST)
    public WebResult queryPage(@RequestBody PageQuery query,
                               @ApiParam(value = "页码") @PathVariable int page,
                               @ApiParam(value = "每页条数") @PathVariable int rowNum) {
        try {
            var user= HsApp.getCurrent();
            query.getQuery().put("receipterSN",user.getUserSN());
            var result = service.queryPage(query, rowNum, page);
            return success("ok", result);
        } catch (Exception ee) {
            return error(ee);
        }
    }
    @ApiOperation(value = "查询站内信息收件信息", notes = "根据用户编号查询站内信未读信息")
    @RequestMapping(value = "/{userSn}", method = RequestMethod.GET)
    public WebResult findByUserSn(@PathVariable String userSn) {
        try{
            var result = service.findByUserSn(userSn);
            if(result!=null){
                return success("查询成功",result.size());
            }else {
                return success("查询成功",0);
            }
        }catch (Exception ee){
            return  error(ee);
        }
    }
}
